Skip to content

Improve APIs for detecting the current country#597

Open
ccawley2011 wants to merge 1 commit intodevkitPro:masterfrom
ccawley2011:country-info
Open

Improve APIs for detecting the current country#597
ccawley2011 wants to merge 1 commit intodevkitPro:masterfrom
ccawley2011:country-info

Conversation

@ccawley2011
Copy link

The CFG_Country enum was generated automatically using the linked test program: https://gist.github.com/ccawley2011/eb97f25dc09a50a9332dcced41d71858

Copy link
Collaborator

@TuxSH TuxSH left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hello, thanks for the PR (and sorry for the delay), I made some minor comments.

The underlying type (from the disassembled impl) for the ISO 3166-1 alpha-2 string seems to be char[3] (2 chars, 1 NUL byte)

CFG_COUNTRY_JO = 177,
CFG_COUNTRY_SM = 184,
CFG_COUNTRY_VA = 185,
CFG_COUNTRY_BM = 186,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There should be:

  • CFG_COUNTRY_OTHER = 254 (used for some niche TWL stuff when restricting CTR country to TWL country enum)
  • CFG_COUNTRY_OTHER = 255 which can be returned by CFGU_GetCountryCodeID

{
u8 unk[2];
u8 state;
u8 country;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

CFG_Country

* @param string Pointer to output the string to. (must contain at least 2 bytes)
*/
Result CFGU_GetCountryCodeString(u16 code, u16* string);
Result CFGU_GetCountryCodeString(u16 code, char *string);
Copy link
Collaborator

@TuxSH TuxSH Feb 28, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actual type for the string is a NUL-terminated 2-char string (thus 3B in total). While char * is correct, a size hint wouldn't hurt; could you use char str[3] please?

Also, while inconsistent with the current rest-of-the-file, I would prefer (char outStr[3], CFG_Country code), likewise w/ the other functions you modified.

Corresponding decomp of the impl:

int __fastcall sub_108038(_DWORD *a1, unsigned int a2)
{
  unsigned int v2; // r6

  if ( a2 >= 0xBB )
  {
    strncpy(a1, (int *)dword_10D280, 3);
    return 0xD90103FA;
  }
  v2 = a2;
  strncpy(a1, (int *)dword_10D284[a2], 3);
  if ( (unsigned int)sub_105D90((char *)dword_10D284[v2]) < 2 )
    return 0xD90103FA;
  return 0;
}

* @param code Pointer to output the country code to. (see @ref CFG_Country)
*/
Result CFGU_GetCountryCodeID(u16 string, u16* code);
Result CFGU_GetCountryCodeID(const char *string, u16* code);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

const char str[3]

* @brief Gets the system's country info.
* @param language Pointer to write the country info to. (see @ref CFG_CountryInfo)
*/
Result CFGU_GetSystemCountryInfo(CFG_CountryInfo* country);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

cfguGetSystemCountryInfo since this is just a wrapper and not an actual IPC command

}

Result CFGU_GetCountryCodeString(u16 code, u16* string)
Result CFGU_GetCountryCodeString(u16 code, char* string)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

char str[3]

if(R_FAILED(ret = svcSendSyncRequest(cfguHandle)))return ret;

*string = (u16)cmdbuf[2] & 0xFFFF;
memcpy(string, &cmdbuf[2], 2);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

2 -> 3 (or manually assign str[2] = '\0';)

}

Result CFGU_GetCountryCodeID(u16 string, u16* code)
Result CFGU_GetCountryCodeID(const char* string, u16* code)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

const char str[3]


Result CFGU_GetSystemCountryInfo(CFG_CountryInfo* country)
{
return CFGU_GetConfigInfoBlk2(4, 0xB0000, country);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

cfguGetSystemCountryInfo (and nit: wrong indentation here)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants